package mop.model.task.field;

import mop.exception.IllegalDescriptionException;
import mop.exception.IllegalIdException;
import mop.exception.IllegalValueException;
import mop.model.ModelInterface;

/**
 * String Field Class
 * 
 * @author MOP Team 7
 */
public class StringField extends Field 
{

	/**
	 * Constructor for StringField class 
	 * @see Field#Field(String, String)
	 */
	public StringField(String id, String description) throws IllegalIdException, IllegalDescriptionException
	{
		super(id, description);
	}
	
	/**
	 * Copy / Clone
	 * 
	 * @param the field to copy
	 * 
	 * @return a copy of this object
	 */
	public StringField clone() 
	{
		StringField n = null;
		try
		{
			n = new StringField(getId(),getDescription());
		}
		catch(Throwable e)
		{
			//impossible at this point
		}
		
		return n;
	}
	
	/***************************************************************************
	 * 						Value
	 ***************************************************************************/
	
	/**
	 * returns the current value
	 * @return this.value
	 */
	public String getValue() 
	{
		if(this.value == null) return "(null)";
		else return this.value;
	}

	/**
	 * Sets the current value to the passed one
	 * 
	 * @param value the new string value
	 * 
	 * @throws IllegalValue Exception
	 * 	!! can never be thrown !! 
	 */
	public void setValue(String value) throws IllegalValueException 
	{
		this.value = value;
	}
	
	/** the value of the field */
	private String value = null;

	/***************************************************************************
	 * 						Model interface
	 ***************************************************************************/
	
	
	/**
	 * get a reference to the interface
	 * @return this
	 */
	public FieldInterface getInterface()
	{
		return this;
	}


        /**
         * return a string view
         * @return this.id - this.description - this.value
         */
        public String toString()
        {
            String a = this.getId()+ "-" +this.getDescription()+"-"+this.getValue();
            return a;
        }
}
